package com.itheima.mall.controller.smsController;


import com.itheima.dto.SmsCouponDto;
import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin    //跨域
@RestController
@RequestMapping("coupon")
public class SmsCouponController {
    @Autowired
    private SmsCouponService smsCouponService;
    //添加优惠劵
    @PostMapping("create")
    private R createCoupon(@RequestBody SmsCouponDto smsCouponDto){
        smsCouponService.createCoupon(smsCouponDto);
        return R.ok(null);
    }
    //删除优惠卷
    @PostMapping("delete/{id}")
    private R deleteCreate(@PathVariable Integer id){
        smsCouponService.deleteCreate(id);
        return R.ok(null);
    }
    //根据优惠券名称和类型分页获取优惠券列表
    @GetMapping("list")
    private R listCreate(@RequestParam(required = false )String name,
                         @RequestParam(required = false) Integer pageNum,
                         @RequestParam(required = false)Integer pageSize,
                         @RequestParam(required = false)Integer type){

     return smsCouponService.getList(name,pageNum,pageSize,type);
    }
    //修改优惠卷
    @PostMapping("update/{id}")
    private R updateCreate(@PathVariable Integer id, @RequestBody SmsCouponDto smsCouponDto){
      smsCouponService.updateCreate(id,smsCouponDto);
      return R.ok(null);
    }
    //获取单个优惠卷的详细信息
    @GetMapping("/{id}")
    private R CouponById(@PathVariable Integer id){
        return  smsCouponService.CouponById(id);
    }
}
